package robocup.testing;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
 * An adapter to close gui-windows
 */
public class WindowClosingAdapter
    extends WindowAdapter {

  private boolean exitSystem;

  /**
   * Contructor of the adapter
   * @param exitSystem if its true, the program is finished
   */
  public WindowClosingAdapter(
      boolean exitSystem) {

    this.exitSystem = exitSystem;
  }

  /**
   * Constructor of the adapter. Program will not be finished.
   */
  public WindowClosingAdapter() {

    this(false);
  }

  /**
   * @see java.awt.event.WindowAdapter#windowClosing(java.awt.event.WindowEvent)
   */
  public void windowClosing(WindowEvent event) {

    event.getWindow().setVisible(false);
    event.getWindow().dispose();
    if (exitSystem) {
      System.exit(0);
    }
  }
}